## Program written by Amelie Davis
## 12/08/2011
## Will count the frequency of words in a text file and send the results to an ouptut text file
## need to have an input file as .txt
## need to have a blank output file as .txt


#name_of_file = raw_input('Please input name of file with path: ')
#file2 = open (name_of_file,"r")
#import sys
#total = sum(int(arg) for arg in sys.argv[1:])

file2 = open ("MissionStatementsTry.txt","r")
text2 = file2.read ()
file2.close ()
word_list2 = text2.lower().split(None)
word_freq2 = {}
for word2 in word_list2:
	word_freq2[word2] = word_freq2.get(word2, 0) + 1

##keys = sorted(word_freq2.keys())
##for word2 in keys:
##	print "%-10s %d" % (word2, word_freq2[word2])

text_file = open("output_text.txt", "w")

for key, value in sorted(word_freq2.iteritems(), key = lambda (k,v): (v,k)):
        #print "%s: %s" % (key, value)
        text_file.write('%s %s\n' % (str(key), ''.join(repr(word_freq2[key]).strip('[]').split(','))))
text_file.close()
##text_file = open("C:\AD\output.txt", "w")
##for key in sorted(word_freq2):
##        text_file.write('%s %s\n' % (str(key), ''.join(repr(word_freq2[key]).strip('[]').split(','))))
##text_file.close()
